<%@page import="util.GlobalParams"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
	if(request.getSession().getAttribute("loginAdmin")==null){
		response.sendRedirect("loginforadmin.html");
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>积分榜</title>
<link type="text/css" href="css/css.css" rel="stylesheet" />
<script type='text/javascript' src="dwr/engine.js"></script>
<script type='text/javascript' src="dwr/util.js"></script>
<script type='text/javascript' src="dwr/interface/DataHelper.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" >
	var PARAMS = { "data": {}, "user":""};
	$(document).ready(function(){
		getScoreList();
	});
	
	getScoreList = function(){
		DataHelper.getScoreList(function(result){
			if (!result.isTrue) {
				alert(result.message);
			}
			else {
				$("#score_list").empty();
				var html ="";
				for(var i=0; i<result.tag.length; i++){
					var obj = result.tag[i];
					PARAMS.data[obj.key] = obj;
					html += "<div class=\"block\" id=\"score_"+obj.key+"\">";
					html += "<div style=\"line-height:25px;\">";
					html += "<strong style=\"width:100px; float:left;\">"+(i+1)+"、"+obj.name+"</strong>";
					html += "<span style=\"float:left;\">积分：<strong>"+obj.score+"</strong></span>";
					html += "<span style=\"float:left; margin-left:20px;\">改分：<input id=\"ipt_"+obj.key+"\" type=\"text\" style=\"width:100px; text-align:right;\"  /></span>";
					html += "<span class=\"sureBtn\" onclick=\"javascript:changeScore('"+obj.key+"');\">确定</span>";
					html += "</div>";
					html += "</div>";
				}
				$("#score_list").append(html);
			}
		});
	};
	
	changeScore = function(key){
		var obj = PARAMS.data[key];
		var score = $.trim($("#ipt_"+key).val());
		var scoreDOM = $("#score_"+key).find("strong").last();
		if(!score.isNum()) {
			alert("请正确填写积分！");
			$("#ipt_"+key).focus();
			return;
		}
		DataHelper.changeScore(key, obj.name, obj.score, score, function(result){
			if (!result.isTrue) {
				alert(result.message);
			}
			else {
				scoreDOM.html((parseFloat(obj.score)+parseFloat(score)).toFixed(2));
			}
		});
	};
	
	clearScore = function(){
		if(window.confirm("确定全部清零？")) {
			DataHelper.clearScore(function(result){
				if (!result.isTrue) {
					alert(result.message);
				}
				else {
					getScoreList();
				}
			});
		}
	};
	
</script>
</head>
<body style="margin:auto; padding:30px; font-size:12px">
	<div style="float:left; width:100%;">
		<span class="sureBtn" style="background: red; margin-left:0px;" onclick="clearScore();" >全部清零</span>
		<strong style="line-height: 20px; margin-left: 10px;">清零算法为：param-Math.round(param), 即将原有积分的邻近整数作为减数进行相减，其中邻近整数为本次需兑现的积分，差值则作为下次的积分基数。</strong>
	</div>
	<div id="score_list" class="matchList">
		<!-- <div class="block" id="match_d8310b0305bd4fec875e40a5f23ea153">
			<div class="title">
				<span style="float:right; line-height: 24px; margin-right: -2px;">
					<span class="sureBtn" onclick="javascript:selWinner('d8310b0305bd4fec875e40a5f23ea153');">下注</span>
				</span><strong style="font-size:20px">希腊VS捷克</strong>
				<span style="margin-left:20px">开始时间：<strong>2012-06-13 00:00:00</strong></span>
			</div>
		</div> -->
	</div>
	
</body>
</html>